package com.bookcode.service;


import com.bookcode.dao.TeacherRepository;
import com.bookcode.entity.Course;
import com.bookcode.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional//一定要添加事务不然删除操作不起作用
public class TeacherService {

    @Autowired
    TeacherRepository teacherRepository;
    //通过工号查找老师
   public  Teacher findTeacherByGonghao(String gonghao){
        return teacherRepository.getTeacherByGonghao(gonghao);
    }
    //通过id找到老师
    public Teacher findTeacherById(Long id){
        return teacherRepository.findById(id).get();
    }
    //通过手机号找到老师
    public Teacher findTeacherByPhone(String phone){
        return teacherRepository.getTeacherByPhone(phone);
    }
    //通过名字查找老师
    public Teacher findTeacherByName(String name){
        return teacherRepository.findTeacherByName(name);
    }
    //查找到所有老师
    public List<Teacher> findAll(){
        return teacherRepository.findAll();
    }
    //添加老师
    public void save(Teacher Teacher){
        teacherRepository.save(Teacher);
    }
    //通过工号删除老师
    public void deleteTeacherByGonghao(String gonghao){
       System.out.println("工号传进到 server层时多少"+gonghao);
        teacherRepository.deleteTeacherByGonghao(gonghao);
    }


//    public List<Course> findCoursesByTeacher(Long teacherId){
//        return teacherRepository.findCoursesByTeacher(teacherId);
//    }

}
